package com.chc.web.park_list.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chc.web.park_list.entity.ParkList;
import com.chc.web.park_list.entity.ParkListParm;
import com.chc.web.park_list.mapper.ParkListMapper;
import com.chc.web.park_list.service.ParkListService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA
 *
 * @Author: chc
 * @Date: 2022/01/14/10:33
 * @Description:
 */
@Service
public class ParkListServiceImpl extends ServiceImpl<ParkListMapper, ParkList> implements ParkListService {
    @Override
    public IPage<ParkList> getList(ParkListParm parkListParm) {
        //构造查询条件
        QueryWrapper<ParkList> query = new QueryWrapper();
        //判断是否有车位名称
        if (StringUtils.isNotEmpty(parkListParm.getParkName())) {
            query.lambda().eq(ParkList::getParkName,parkListParm.getParkName());
        }
        //判断是否有使用状态
        if (StringUtils.isNotEmpty(parkListParm.getParkStatus())){
            query.lambda().eq(ParkList::getParkStatus,parkListParm.getParkStatus());
        }
        //判断是否有车位类型
        if (StringUtils.isNotEmpty(parkListParm.getParkType())){
            query.lambda().eq(ParkList::getParkType,parkListParm.getParkType());
        }
        //构造分页条件
        IPage<ParkList> page = new Page<>();
        page.setCurrent(parkListParm.getCurrentPage());
        page.setSize(parkListParm.getPageSize());
        return this.baseMapper.selectPage(page,query);
    }
}
